package com.epam.zhilko.entity;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;

/**
 * Created with IntelliJ IDEA.
 * User: admin
 * Date: 11/26/13
 * Time: 9:50 AM
 * To change this template use File | Settings | File Templates.
 */


@NamedQueries({
        @NamedQuery(name = "findEmployeeByName", query = "SELECT e FROM EMPLOYEE e WHERE e.name = :name"),
        @NamedQuery(name = "findEmployeeDepartmentByID", query = "SELECT p.name FROM PROJ p JOIN p.employees d WHERE d.id = :id")

})

@Entity(name = "EMPLOYEE")
public class Employee {


    private int id;
    private String name;
    private Department department;
    private Collection<Project> projects = new ArrayList<Project>();
    private Vehicle vehicle;

    @Embedded
    @AttributeOverrides({
            @AttributeOverride(name = "VEHICLE_MAKE", column = @Column(name = "CAR_MAKE")),
            @AttributeOverride(name = "VEHICLE_MODEL", column = @Column(name = "CAR_MODEL"))})
    public Vehicle getVehicle() {
        return vehicle;
    }

    public void setVehicle(Vehicle vehicle) {
        this.vehicle = vehicle;
    }

    @ManyToMany(cascade = CascadeType.PERSIST)
    public Collection<Project> getProjects() {
        return projects;
    }

    public void setProjects(Collection<Project> projects) {
        this.projects = projects;
    }

    @ManyToOne(cascade = CascadeType.PERSIST)
    @JoinColumn(name = "DEPT_ID")
    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "EMP_ID")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Column(name = "EMP_NAME", nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String toString() {
        return this.getId() + this.getName() + this.getDepartment();
    }

}
